﻿<html xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

<head>
</head>

<body>
<!-- When viewing in Visual Studio, choose the Design button for easier reading. -->
<p>The Query Visualizer is an assembly that can be used in a Visual Studio debug session to visualize database queries. 
	The project itself is just a library, and cannot be run. If you compile it, a 
	library (DLL) is generated that can be used in Visual Studio to enhance your 
	ability to debug LINQ to SQL applications.</p>

<p class="MsoNormal"><strong>NOTE</strong>: When you are debugging applications 
with the Visualizer you may need to add &quot;<span style="color: #A31515">Persist Security Info=true&quot; </span>
to the connection string. When the debugger is 
activated it serializes information from the program being debugged and sends it 
over to the process which displays the visualizer.&nbsp; One of the pieces of 
information that is serialized is the connection string which is obtained from 
the SqlConnection object. By default, the SqlConnection object doesn’t return the password 
and therefore the connection string without the password is serialized 
and sent over to the visualizer.&nbsp; When you attempt to execute the query in 
the visualizer it may fail because it doesn’t have the password.&nbsp; </span>
Only use this setting when debugging. It isn’t recommended for production.&nbsp;</p>
<p>To use the Visualizer the DLL generated by the <strong>LinqToSqlQueryVisualizer</strong> project must be copied 
to the <strong>...\Documents\Visual Studio 2008\Visualizers </strong>directory. You may need to create the 
<strong>Visualizers</strong> directory. In pre-Vista 
versions of Windows use the <strong>My Documents</strong> directory rather than <strong>Documents</strong>. 
If you have the rights, you can also copy the file to:

 <strong>...\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers.</strong></p>

<p>Here is a step by step outline of what to do:</p>
<ul>
	<li>Build the Query Visualizer</li>
	<li>Copy the DLL produced by the compilation from the bin directory of your project 
	into the <strong>Visualizers</strong> directory</li>
	<li>If necessary, close Visual Studio and reopen to make sure the Visualizer 
	is recognized</li>
	<li>You can test the visualizer in an existing sample project, such as 
	<strong>SampleQueries</strong></li>
	<li>Alternatively you can create a default console application in which to test the visualizer</li>
	<li>To begin creating your own test harness, first create a default console application</li>
	<li>Use the LINQ to SQL Designer to attach to the Northwind database that 
	ships with the samples.<ul>
		<li>Bring up the <strong>Add New Item</strong> dialog (Ctrl-Shift-A)</li>
		<li>Choose <strong>LINQ to SQL classes</strong></li>
		<li>Bring up the <strong>Server Explorer</strong> (Ctrl-W, L)</li>
		<li>Choose the <strong>Connect to Database</strong> button in the 
		Explorer. If necessary, select Microsoft SQL Server Database File as the 
		Data source. Browse for the <strong>Northwind.mdb</strong> database in the <strong>Data</strong> directory that ships with the samples.</li>
		<li>Drag the <strong>Customers </strong>table on to the the designer.</li>
	</ul>
	</li>
	<li>Write and call a simple query such as the one shown below called <strong>
	SimpleQuery()</strong>:</li>
	<li>Put a breakpoint on the <strong>foreach</strong> line and run to it.</li>
	<li>Hover the mouse over the word <strong>query</strong> and pop up the Visualizer by 
	clicking on the magnifying glass:
	<img alt="Magnify" src="Magnify.png" width="33" height="16"><br>
	</li>
</ul>
<pre>        public void SimpleQuery()
        {
            DataClasses1DataContext db = new DataClasses1DataContext();

            var query = from c in db.Customers
                        select c;

            foreach (var item in query)
            {
                Console.WriteLine(item.CompanyName);
            }
        }
</pre>

</body>
</html>
